<{extends file="$elementPath/layout/index.html"}>
<{block name='body'}>
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form layui-form-pane" action="">
            <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list"
                 style="padding: 20px ;">
                <div class="layui-form-item">
                    <label class="layui-form-label">上级菜单</label>
                    <div class="layui-input-block">
                        <select class="chosen-select" name="parentid">
                            <option value="0">顶级菜单</option>
                            <{foreach from=$topmenus item=item}>
                            <option value="<{$item->id}>"
                            <{if isset($data)}><{if $data->parentid eq $item->id}>selected="selected"<{/if}><{/if}>
                            ><{$item->title}></option>
                            <{/foreach}>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">菜单名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="title" value="<{if isset($data)}><{$data->title}><{/if}>"
                               lay-verify="required"
                               placeholder="请输入菜单名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">URL</label>
                    <div class="layui-input-inline">
                        <input type="text" name="url" value="<{if isset($data)}><{$data->url}><{/if}>"
                               placeholder="输入菜单链接地址"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">ICON</label>
                    <div class="layui-input-inline">
                        <input type="text" name="icon"
                               value="<{if isset($data)}><{$data->icon}><{else}>layui-icon-home<{/if}>"
                               lay-verify="required" placeholder="icon" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">权重</label>
                    <div class="layui-input-inline">
                        <input type="text" name="sort"
                               value="<{if isset($data)}><{$data->sort}><{else}>0<{/if}>"
                               lay-verify="number" placeholder="数字越大越靠前" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <input type="button" lay-submit lay-filter="role-form-submit" id="role-form-submit"
                           value="确认">
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    layui.use(['index', 'form'], function () {
        var $ = layui.$
            , form = layui.form;

        //监听提交
        form.on('submit(role-form-submit)', function (data) {
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

            //提交 Ajax 成功后，关闭当前弹层并重载表格
            //$.ajax({});
            $.post('/<{$module}>/<{$controller}>/<{$action}>/id/<{if isset($data)}><{$data->id}><{/if}>?isajax=1&', field, function (res) {
                if (res.code == 0) {
                    //ok
                    parent.layui.table.reload('menu-table-page'); //重载表格
                    parent.layer.close(index); //再执行关闭
                } else {
                    layer.msg(res.msg);
                }
            }, 'json')
        });
    })
</script>
<{/block}>